package cn.wolfcode.domain;

import cn.wolfcode.enums.QuestionTypeEnum;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
public class Question {
    /** */
    private Long id;
    /** 标题*/
    private String title;
    /** 类型(单选/多选/判断)*/
    private Integer type;
    /** 判断正确(针对判断题才有此项)*/
    private boolean judgeRight;
    //问题对应的选项集合
    private List<QuestionItem> questionItems = new ArrayList<>();
    //每题的分数
    private Integer score;
    //每题的序号
    private Integer sequence;
    private String typeName;

    public String getTypeName(){
        return QuestionTypeEnum.findName(this.type);
    }

    public String toString(){
        return JSON.toJSONString(this);
    }
    public String getAns(){
        StringBuilder sb = new StringBuilder();
        if(questionItems != null){
            for (QuestionItem item : questionItems) {
                if(item.isJudgeRight()){
                    sb.append(item.getTitle(), 0, 1);
                }
            }
        }
        return sb.toString();
    }

}